package karileet.meeting.profile.fragment;

import android.content.res.Resources;
import karileet.meeting.profile.ProfileConf;
import karileet.meeting.profile.R;
import karileet.meeting.profile.list.holder.ListCheckboxItemHolder;
import karileet.meeting.profile.list.item.ListCheckboxItem;
import karileet.meeting.profile.model.Weekdays;

import java.util.ArrayList;
import java.util.List;

/**
 * List shows days of week that user can then enable or disable (for scheduled start/stop)
 */
public class WeekdayListFragment extends AbstractListFragment {

    @Override
    protected void onClickAction(ListCheckboxItemHolder holder, int position) {
        ProfileConf config = new ProfileConf(getActivity());
        Weekdays wd = config.getWeekdays();
        // pass isChecked directly, since it is toggled in abstract class already!
        wd.set(position, holder.getCb().isChecked());
        config.setWeekdays(wd);
    }

    protected List<ListCheckboxItem> populateMainList() {
        Resources res = getResources();
        String[] titles = res.getStringArray(R.array.listWeekdays);
        ProfileConf config = new ProfileConf(getActivity());
        Weekdays wd = config.getWeekdays();
        List<ListCheckboxItem> list = new ArrayList<ListCheckboxItem>();
        int i = 0;
        for (String day : titles) {
            list.add(new ListCheckboxItem(day, "", wd.isDayEnabled(i)));
            i++;
        }

        return list;
    }

}
